
= simple_form_for(@part_stockin_detail, html: {class: 'form-vertical', novalidate: true}, wrapper: :vertical_form) do |o|
  .row
	  .col-md-12.hidden
	    = o.input :part_stockin_id, input_html: { value: params[:id] }
	  .col-md-12

	    = o.input :part_style_id, collection: @part_styles, as: :collection_select, label: '分类'

	    = o.input :part_id, collection: @part_styles, as: :grouped_collection_select, group_method: :parts, label: '配件'

	    = o.input :qty, label: '数量'

	    = o.button :submit, "保存", :class => 'btn-success btn-xs'


coffee:
  jQuery ->
    $('#part_stockin_detail_part_id').parent().hide()
    parts = $('#part_stockin_detail_part_id').html()
    $('#part_stockin_detail_part_style_id').change ->
      part_style = $('#part_stockin_detail_part_style_id :selected').text()
      escaped_part_style = part_style.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1')
      options = $(parts).filter("optgroup[label='#{escaped_part_style}']").html()
      if options
        $('#part_stockin_detail_part_id').html(options)
        $('#part_stockin_detail_part_id').parent().show()
      else
        $('#part_stockin_detail_part_id').empty()
        $('#part_stockin_detail_part_id').parent().hide()